Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add XBitmap support (direct usage GIMP *.xbm files) #31

Merged
merged 4 commits into from Sep 22, 2014

Conversation

subsonicpulse
Copy link
Contributor

Draw XBitMap Files (*.xbm), exported from GIMP,
Usage:
Export from GIMP to *.xbm, rename *.xbm to *.c and open in editor.
C Array can be directly used with this function
void Adafruit_GFX::drawXBitmap(int16_t x, int16_t y,
const uint8_t *bitmap, int16_t w, int16_t h,
uint16_t color)

add XBitmap(*.xbm) support, to directly use exported GIMP xbm files. (Rename the file to *.c and open in editor.)
add XBitmap(*.xbm) support, to directly use exported GIMP xbm files. (Rename the file to *.c and open in editor.)
Add description of XBitMap support extension.
refine description
@subsonicpulse
Copy link
Contributor Author

Tested with Adafruit_SSD1306. Picture from a In-Car project.
foto 15 04 14 22 52 44

@subsonicpulse subsonicpulse changed the title Add XBitmap support Add XBitmap support (direct usage GIMP *.xbm files) Apr 28, 2014
@ZaioBaio
Copy link

Very nice fix. Why it is not already merged to the master branch?

@tdicola tdicola merged commit d9f6c67 into adafruit:master Sep 22, 2014
@tdicola
Copy link
Contributor

tdicola commented Sep 22, 2014

Thanks for submitting the change and apologies it took a little while to be reviewed. Looks like a great change--thanks for adding some comments on the usage, etc. I tested it out and it works really well. Just merged in the change, thanks!

@griffdrummer
Copy link

Just as a heads up, to use the "drawXBitmap" function, I also had to redefine the array from "static unsigned char" to "static const uint8_t PROGMEM" in my image file. If I just used the original file, then garbage would appear on my 32x32 gird. I think the array has to be defined as "PROGMEM" because the "drawXBitmap" function uses the "pgm_read_byte" function, which reads a byte from program memory. I also had to include the line "#include <avr/pgmspace.h>". After that, everything worked fine for me.

@tdicola
Copy link
Contributor

tdicola commented Nov 24, 2014

Oh yep, the function does assume the data is in flash memory by using the PROGMEM attribute. Thanks for digging in and commenting on what you found so other folks can learn from it too!

@svgeesus
Copy link

Hello griffdrummer,

Sunday, November 23, 2014, 10:58:55 PM, you wrote:

Just as a heads up, to use the "drawXBitmap" function, I also had
to redefine the array from "static unsigned char" to "static const
uint8_t PROGMEM" in my image file.

Ideally it would be const static unsigned uint8_t PROGMEM so that on
ARM processors (and on more recent compilers for AVR) it still works
and still gets put into Flash rather than SRAM.

Best regards,
Nantonos mailto:nantonos@epona.net

@seb155
Copy link

seb155 commented Dec 31, 2016

Hi,
I've try the drawXBitmap function, but it doesn't seem to work on a ARDUINO_ARCH_ARC32 (Arduino 101).
Result on the matrix seem to be random pixel.
I use a static const uint8_t PROGMEM:

// My bitmap exported by GIMP ".xbm"
static const uint8_t PROGMEM xbitmap [] = {
0x80, 0xff, 0x00, 0x70, 0x15, 0x03, 0x70, 0x02, 0x03, 0x88, 0x0a, 0x0c,
0x06, 0x05, 0x10, 0xa6, 0x14, 0x10, 0x46, 0x00, 0x10, 0x0b, 0xa0, 0x60,
0x13, 0x00, 0x75, 0x0b, 0x40, 0x65, 0x13, 0x00, 0x61, 0x13, 0x20, 0x60,
0x21, 0x40, 0x60, 0x43, 0x29, 0x60, 0x21, 0x52, 0x60, 0xd1, 0xff, 0x61,
0xe1, 0xff, 0x75, 0x3e, 0x23, 0x1e, 0x08, 0x22, 0x0c, 0x08, 0x22, 0x0c,
0x08, 0x00, 0x0c, 0x30, 0x00, 0x02, 0xc0, 0xdd, 0x01, 0xc0, 0xff, 0x01 };

// code
matrix.drawXBitmap(0, 0, xbitmap, 32, 24, 0xff);

If I use the drabitmap with the image2cpp converter "http://javl.github.io/image2cpp/"
Picture show up correctly on my led matrix.

Can it be a problem with the function "pgm_read_byte()" ??

@subsonicpulse
Copy link
Contributor Author

Can you paste the xbm file content?
It seems it has not the right proportions. when i import it to GIMP then it needs to be 24x32 to get a mushroom picture. Otherwise its just snow. :-)
maybe you need to re-create it with the right aspect ratio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants